Skip to content

fix(python): fix snippet regressions in reference.md and docstrings#14668

Merged
aditya-arolkar-swe merged 8 commits intomainfrom
devin/1775495102-fix-python-sdk-snippet-regressions
Apr 7, 2026
Merged

fix(python): fix snippet regressions in reference.md and docstrings#14668
aditya-arolkar-swe merged 8 commits intomainfrom
devin/1775495102-fix-python-sdk-snippet-regressions

Conversation

@aditya-arolkar-swe
Copy link
Copy Markdown
Contributor

@aditya-arolkar-swe aditya-arolkar-swe commented Apr 6, 2026

Summary

Fixes three regressions in generated Python SDK snippets (reference.md, README, and docstrings) that were introduced when snippet generation moved from the Python v1 generator to the TypeScript v2 dynamic snippets generator in v4.62.0.

1. Enums rendered as strings

When pydantic_config.enum_type is set to python_enums or forward_compatible_python_enums, enum parameters in reference.md/README snippets were rendered as raw strings (e.g. side="BUY") instead of enum references (SideTypeCode.BUY).

Root cause: DynamicTypeLiteralMapper.convertEnum() always emitted string literals and never checked the enum_type config. Additionally, SdkCustomConfigSchema.parse() silently stripped pydantic_config from the custom config before passing it to the dynamic snippets generator.

Fix: Pass raw config.customConfig instead of the parsed/stripped version to DynamicSnippetsGenerator, and check pydantic_config.enum_type in convertEnum() and synthesizeDefaultNamed() to emit proper enum member access.

2. Objects and discriminated unions rendered as dict literals

Objects and discriminated unions in snippets were rendered as dict literals (e.g. order_type={"type": "MARKET"}, instrument={"symbol": "AAPL US Equity"}) instead of Pydantic model constructors (OrderType_Market(), InstrumentSymbol(symbol="AAPL US Equity")).

Root cause: convertObject() was gated on useTypedDictRequests(), and convertDiscriminatedUnion() had no Pydantic constructor path at all — it always emitted TypedDicts.

Fix: Always use Pydantic model constructors for both objects and discriminated unions in snippets. Added getDiscriminatedUnionVariantClassReference() to resolve variant class names (e.g. OrderType + MarketOrderType_Market).

3. Missing OAuth credentials in docstring snippets

OAuth client credentials client instantiation in docstrings showed client = Orders() with no auth params.

Root cause: build_default_snippet_kwargs() only includes params without defaults, but client_id/client_secret have os.getenv(...) defaults.

Fix: Explicitly append client_id/client_secret with placeholder values when OAuth client credentials are configured.

Test plan

  • Verified against a real customer fixture with OAuth + enums + discriminated unions
  • Seed output matches the correct behavior from generator v4.48.0
  • CI seed tests pass

…h params in docstrings

- Fix DynamicTypeLiteralMapper.convertEnum() to render enum references
  (e.g., Operand.GREATER_THAN) instead of string literals when using
  python_enums or forward_compatible_python_enums pydantic config
- Fix build_default_snippet_kwargs() to include client_id and
  client_secret in OAuth client credentials docstring examples
- Also fix synthesizeDefaultNamed() for consistent enum rendering

Co-Authored-By: adi <aditya.arolkar@berkeley.edu>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

SDK Generation Benchmark Results

Comparing PR branch against main baseline.

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
python-sdk square N/A N/A 182s N/A

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).

…dantic_config

Co-Authored-By: adi <aditya.arolkar@berkeley.edu>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

SDK Generation Benchmark Results

Comparing PR branch against main baseline.

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
python-sdk square N/A N/A 176s N/A

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).

@devin-ai-integration devin-ai-integration bot changed the title fix(python-sdk): fix enum representation in snippets and missing OAuth params in docstrings fix(python): fix enum representation in snippets and missing OAuth params in docstrings Apr 7, 2026
…tructors in snippets

Since v4.62.0, reference.md and README snippets rendered objects as dict
literals when use_typeddict_requests was enabled, and discriminated unions
as dicts unconditionally. This regressed from the v1 generator which
always used Pydantic model constructors (e.g. OrderType_Market() instead
of {"type": "MARKET"}).

- Always use Pydantic constructors for objects in convertObject() and
  synthesizeDefaultNamed(), removing the useTypedDictRequests() gate
- Add Pydantic constructor path for discriminated unions in
  convertDiscriminatedUnion() with variant class resolution
- Add getDiscriminatedUnionVariantClassReference() to construct variant
  class names (e.g. OrderType_Market from OrderType + Market)

Made-with: Cursor
…75495102-fix-python-sdk-snippet-regressions
@fern-support fern-support changed the title fix(python): fix enum representation in snippets and missing OAuth params in docstrings fix(python): fix snippet regressions in reference.md and docstrings Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

SDK Generation Benchmark Results

Comparing PR branch against main baseline.

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
python-sdk square N/A N/A 168s N/A

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).

@aditya-arolkar-swe aditya-arolkar-swe enabled auto-merge (squash) April 7, 2026 16:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

SDK Generation Benchmark Results

Comparing PR branch against main baseline.

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
python-sdk square N/A N/A 167s N/A

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).

@aditya-arolkar-swe aditya-arolkar-swe merged commit e14a749 into main Apr 7, 2026
93 checks passed
@aditya-arolkar-swe aditya-arolkar-swe deleted the devin/1775495102-fix-python-sdk-snippet-regressions branch April 7, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants